<?php
session_start();
require('./include/class_com_function.php');
if(!isset($_SESSION['checksum']))
	$_SESSION['checksum'] = isa_getRandstr(10); 
$title = "在线报名 &laquo; 创软俱乐部";
?>
<!DOCTYPE HTML>
<html lang="zh_cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<title>在线报名 &laquo; 创软俱乐部 </title>
<link href="./css/common.css" rel="stylesheet" type="text/css">
<link href="./css/style.css" rel="stylesheet" type="text/css">
<?php 
if(!isset($_POST['success_name']) && !isset($_POST['name']))
{
echo <<<JS
<script type="text/javascript" src="./js/verify.js"></script>
<script type="text/javascript" src="./js/message.js"></script>
<script type="text/javascript" src="./js/form.js"></script>
<link href="./css/message.css" rel="stylesheet" type="text/css">
JS;
}
?>
</head>
<body>
<?php 
require('./data/class_join_people.php');
if(isset($_POST['success_name']))
{
	$_success['name'] = $_POST['success_name'];
	$_success['mail'] = $_POST['success_mail'];
	$_success['ip'] = $_POST['success_ip'];
	unset($_SESSION['checksum']);
	require('./content/join_success.php');
}
else if(isset($_POST['name']))
{
	$name = $_POST['name'];
	$number = $_POST['number'];
	$class = $_POST['class'];
	$telphone = $_POST['telphone'];
	$email = $_POST['email'];
	$checksum = $_POST['checksum'];
	$ip = $_SERVER["REMOTE_ADDR"];
	
	if(!isset($_SESSION['checksum']) || $_SESSION['checksum'] != $checksum)
	{
		echo "非法访问！";
		exit(0);
	}
	
	$join = new isa_join_people($name, $number, $class, $telphone, $email, $ip);
	
	if($join->CheckRepeat())
	{
		$_warning['t'] = "repeat";
		require('./content/join_warning.php');
	}
	else if(!filter_var($email, FILTER_VALIDATE_EMAIL))
	{
		$_warning['t'] = "mail";
		require('./content/join_warning.php');
	}
	else
	{
		try 
		{
			$result = $join->Submit();
			if($result)
			{			
				
				echo '<form id="subform" action="#" method="post">';
				echo '<input type="hidden" name="success_name" value="'.$name.'"/>';
				echo '<input type="hidden" name="success_mail" value="'.$email.'"/>';
				echo '<input type="hidden" name="success_ip" value="'.$ip.'"/>';
				echo '</form>';
				echo '<script>';
				echo 'document.getElementById("subform").submit();';
				echo '</script>';
			}
		} 
		catch (Exception $e) {
			$_warning['t'] = "error";
			$_warning['meg'] = $e->getMessage();
			require('./content/join_warning.php');
		}
		
	}
}
else
{
	require_once('./content/join_form.php');
}
require('./content/join_footer.php');
?>
</body>
</html>
